package org.firebug.metadata.micro.repository.dao;

import org.apache.ibatis.annotations.*;
import org.firebug.metadata.micro.repository.po.DictionaryPO;

import java.util.List;

@Mapper
public interface DictionaryDAO {
    @Insert("insert into t_dictionary (pcode,code,name,value,sectors) values (#{pcode},#{code},#{name},#{value},#{sectors})")
    int insert(DictionaryPO po);

    @Update("<script>" +
            "update t_dictionary set deleted=1 where code in " +
            "<foreach collection='code' item='item' index='index' open='(' separator=',' close=')'>" +
            "${item}" +
            "</foreach>" +
            "</script>")
    int deleteByCode(@Param("code") String... code);

    @Select("select * from t_dictionary where code=#{code}")
    DictionaryPO selectByCode(@Param("code") String code);

    @Select("select * from t_dictionary where pcode=#{pcode} and deleted=0")
    List<DictionaryPO> selectByPcode(@Param("pcode") String pcode);

    @Select("select * from t_dictionary where pcode=#{pcode} and deleted=0 and sectors & 1<<${sector}")
    List<DictionaryPO> selectByPcodeSector(@Param("pcode") String pcode, @Param("sector") int sector);
}
